	package browser.service;

	import browser.dao.UserInfo;
	import java.io.*;
	import java.sql.*;
	import javax.servlet.*;
	import javax.servlet.http.*;

	/**
	 * Servlet that displayes the title, the time user logged in and user id on the top
	 * of web page
	 */
	public class Banner extends HttpServlet {

		public static Connection conn;
		public static Statement stmt;

		public void doGet(HttpServletRequest request,
				HttpServletResponse response) throws ServletException,
				IOException {

			doPost(request, response);
		}

		public void doPost(HttpServletRequest request,
				HttpServletResponse response) throws ServletException,
				IOException {

			response.setContentType("text/html");
			PrintWriter out = response.getWriter();

			String uid[] = request.getParameterValues("uid");
			String uacc[] = request.getParameterValues("uAccess");

			try {
				Class.forName("oracle.jdbc.driver.OracleDriver");
			} catch (ClassNotFoundException e) {
				out.println("Error loading the Driver:" + e.getMessage());
				return;
			}

			Connection conn = null;
			UserInfo user = MyUtilities.getUserInfo(uid[0]);

			if (!uacc[0].equals(user.getUaccess())) {
				out.print("Please login first");
				return;
			}
			try {
				conn = DriverManager.getConnection("jdbc:oracle:thin:"
						+ user.getUid() + "/" + user.getPassword()
						+ "@oraserver.cs.luc.edu:1521:cs");
			} catch (SQLException e1) {
				out.println("Error connecting to Oracle:" + e1.getMessage());
				return;
			}
			if (conn == null) {
				out.println("Null Connection");
				return;
			}

			out.println("<html>");
			out.println("  <head>");
			out.println("    <title>Banner</title>");
			out.println("<link type=\"text/css\" rel=\"stylesheet\" href=\"main.css\"/>");
			out.println("  </head>");
			out.println("  <body> ");
			out.println("<div id=\"header\">");
			out.println("  <center> ");
			out.println("<table id=\"table\">");
			out.println("<tr>");
			out.println("<td>");
			out.println("<img src=\"Logo.jpg\">");
			out.println("</td>");
			out.println("<td>");
			out.println("<h1>Loyola Oracle Database Browser Plus</h1>");
			out.println("<em><strong>Time when logged in: " + new java.util.Date()+ "</strong></em>");
			out.println("</br>");
			out.println("<font size=3><em>Oracle schema: " + uid[0]+ "'s schema</em></font>");
			out.println("</td>");
			out.println("<td>");
			out.println("<form action=\"/DatabaseBrowser/Logout\" method=\"post\">");
			out.println("<input type=\"hidden\" name=\"uid\" value=\"" + uid[0]+ "\">");
			out.println("<input type=\"submit\" value=\"Log out\">");
			out.println("</form>");
			out.println("</td>");
			out.println("</tr>");
			out.println("</table>");
			out.println("  </center> ");
			out.println("</div>");

			out.println("  </body> ");
			out.println("</html>");

			try {
				conn.close();
			} catch (SQLException e) {
				out.println("executeQuery " + e.getMessage());
				return;
			}

			out.close();
		}

		public String getServletInfo() {
			return "This Servlet processes Banner";
		}

	}
